package com.zx.cloud.controller;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.zx.cloud.ApiVersion;
import com.zx.cloud.RequestLogging;
import com.zx.cloud.common.auth0.jwt.Token;
import com.zx.cloud.common.filter.CurrentUserId;
import com.zx.cloud.common.filter.IgnoreAuth;
import com.zx.cloud.controller.client.ProviderClient;
import com.zx.cloud.domain.Client;
import com.zx.cloud.domain.ClientAuth;
import com.zx.cloud.domain.CollegeDepartment;
import com.zx.cloud.domain.Dict;
import com.zx.cloud.domain.IdCardImg;
import com.zx.cloud.domain.Provinces;
import com.zx.cloud.domain.SmsMsg;
import com.zx.cloud.domain.VerifyMsg;
import com.zx.cloud.model.response.ObjectDataResponse;
import com.zx.cloud.model.response.Response;

import io.swagger.annotations.ApiOperation;

/**
 * @author Alex
 */
@RestController
@RequestMapping(value = ApiVersion.API_V1_PREFIX+"/client", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE}, consumes = {MediaType.APPLICATION_JSON_UTF8_VALUE})
public class UserController {
	
    @Autowired
    private ProviderClient providerClient;
    
    @IgnoreAuth
    @ApiOperation(value = "手机会员注册" , notes = "手机会员注册")
	@RequestMapping(value = "clientRegister", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Token> clientRegister(@RequestBody Client client){
    	final ObjectDataResponse<Token> datas = providerClient.clientRegister(client);
		return datas;
	}
    
    @IgnoreAuth
    @ApiOperation(value = "会员登录操作" , notes = "会员登录操作")
	@RequestMapping(value = "clientLogin", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Token> clientLogin(@RequestBody  Client client){
    	final ObjectDataResponse<Token> datas = providerClient.clientLogin(client);
		return datas;
	}
    
	@ApiOperation(value = "会员刷新TOKEN操作" , notes = "会员刷新TOKEN操作")
	@RequestMapping(value = "refreshToken", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Token> refreshToken(@CurrentUserId Long userId){
		final ObjectDataResponse<Token> datas = providerClient.refreshToken(userId);
		return datas;
	}
    
    @IgnoreAuth
    @ApiOperation(value = "会员忘记密码" , notes = "会员忘记密码")
	@RequestMapping(value = "forgotPassword", method = RequestMethod.POST)
	@ResponseBody
	public Response forgotPassword(@RequestBody Client client){
    	final ObjectDataResponse<Integer> datas = providerClient.forgotPassword(client);
		return datas;
	}
    
    @ApiOperation(value = "会员修改密码" , notes = "会员修改密码")
	@RequestMapping(value = "modifyPassword", method = RequestMethod.POST)
	@ResponseBody
	public Response modifyPassword(@CurrentUserId Long userId,@RequestBody Client client){
    	final ObjectDataResponse<Integer> datas = providerClient.modifyPassword(client);
		return datas;
	}
    
    @ApiOperation(value = "获取会员认证信息" , notes = "获取会员认证信息")
	@RequestMapping(value = "getClientAuth", method = RequestMethod.POST)
	@ResponseBody
	public Response getClientAuth(@CurrentUserId Long userId,@RequestBody Client client){
    	final ObjectDataResponse<ClientAuth> datas = providerClient.getClientAuth(client);
		return datas;
	}
    
    @IgnoreAuth
    @ApiOperation(value = "验证手机-获取验证码" , notes = "验证手机-获取验证码")
	@RequestMapping(value = "sendSMS", method = RequestMethod.POST)
	@ResponseBody
	public Response sendSMS(@CurrentUserId Long userId,@RequestBody SmsMsg smsMsg){
    	final ObjectDataResponse<Integer> datas = providerClient.sendSMS(smsMsg);
		return datas;
	}
    
    @IgnoreAuth
    @ApiOperation(value = "判断验证码对错" , notes = "判断验证码对错")
	@RequestMapping(value = "verifyCode", method = RequestMethod.POST)
	@ResponseBody
	public Response verifyCode(@CurrentUserId Long userId,@RequestBody SmsMsg smsMsg){
    	final ObjectDataResponse<Integer> datas = providerClient.verifyCode(smsMsg);
		return datas;
	}
    
    @IgnoreAuth
    @ApiOperation(value = "获取中国各大银行" , notes = "获取中国各大银行")
	@RequestMapping(value = "getBanks", method = RequestMethod.POST)
	@ResponseBody
	public Response getBanks(){
    	final ObjectDataResponse<List<Dict>> datas = providerClient.getBanks();
		return datas;
	}
    
    
    @ApiOperation(value = "身份认证—保存身份证信息" , notes = "身份认证—保存身份证信息")
 	@RequestMapping(value = "handleClientIDCardMsg", method = RequestMethod.POST)
 	@ResponseBody
 	public ObjectDataResponse<Integer> handleClientIDCardMsg(@CurrentUserId Long userId, @RequestBody VerifyMsg verifyMsg){
     	final ObjectDataResponse<Integer> datas = providerClient.handleClientIDCardMsg(verifyMsg);
 		return datas;
 	}
    @RequestLogging
	@ApiOperation(value = "身份认证—保存身份证图片" , notes = "身份认证—保存身份证图片")
	@RequestMapping(value = "saveIDCardImg", method = RequestMethod.POST)
	@ResponseBody
	public Response saveIDCardImg(@CurrentUserId Long userId,@RequestBody IdCardImg idCardImg){
    	idCardImg.setClientId(userId);
		
		return  providerClient.saveIDCardImg( idCardImg);
	}
 
    
    @IgnoreAuth
    @ApiOperation(value = "查询全国高校信息" , notes = "查询全国高校信息")
	@RequestMapping(value = "collegeMsg", method = RequestMethod.POST)
	@ResponseBody
	public Response collegeMsg(@RequestBody  Client client){
    	final ObjectDataResponse<List<CollegeDepartment>> datas = providerClient.collegeMsg(client);
		return datas;
	}
    
    @IgnoreAuth
    @ApiOperation(value = "查询省市区信息" , notes = "查询省市区信息")
	@RequestMapping(value = "provinceMsg", method = RequestMethod.POST)
	@ResponseBody
	public Response provinceMsg(@RequestBody  Client client){
    	final ObjectDataResponse<List<Provinces>> datas = providerClient.provinceMsg(client);
		return datas;
	}
    
    @IgnoreAuth
    @ApiOperation(value = "获取职业" , notes = "获取职业")
	@RequestMapping(value = "getOccpation", method = RequestMethod.POST)
	@ResponseBody
	public Response getOccpation(){
    	final ObjectDataResponse<List<Dict>> datas = providerClient.getOccpation();
		return datas;
	}
    
    @IgnoreAuth
    @ApiOperation(value = "获取学历" , notes = "获取学历")
	@RequestMapping(value = "getEducation", method = RequestMethod.POST)
	@ResponseBody
	public Response getEducation(){
    	final ObjectDataResponse<List<Dict>> datas = providerClient.getEducation();
		return datas;
	}

}
